/**
 * 
 */
package com.java.test.paymanage.controller;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONObject;
import com.java.test.controller.BaseController;
import com.java.test.paymanage.dto.OnlinePayInfo;
import com.java.test.paymanage.dto.PayChannelInfo;
import com.java.test.paymanage.dto.PayTypeInfo;
import com.java.test.paymanage.dto.RechargeDiscountInfo;
import com.java.test.paymanage.dto.SkAccountInfo;
import com.java.test.paymanage.service.PayManageService;
import com.java.test.system.dto.LoginAccountInfo;
import com.java.test.util.HttpErrorCode;
import com.java.test.util.JsonResult;
import com.java.test.util.JsonUtil;

/**
 * @author Administrator
 *
 */
@RestController
@RequestMapping("/paymanage")
public class PayManageController extends BaseController {

	@Autowired
	PayManageService payManageService;

	/**
	 * 支付类型列表
	 * 
	 * @return
	 */
	@RequestMapping("/paytypeList")
	public JsonResult paytypeList() {
		JsonResult js = new JsonResult(HttpErrorCode.REQUESTSUCCESS.getCode(),
				HttpErrorCode.REQUESTSUCCESS.getContent());
		try {
			List<PayTypeInfo> list = payManageService.selectpaytypeList();
			if (list == null) {
				js.setCode(HttpErrorCode.PARAMERROR.getCode());
				js.setMessage(HttpErrorCode.PARAMERROR.getContent());
				return js;
			}
			list = list.stream().sorted(Comparator.comparing(PayTypeInfo::getSort).reversed())
					.collect(Collectors.toList());

			js.setData(list);
		} catch (Exception e) {
			e.printStackTrace();
			js.setCode(HttpErrorCode.SERVICEERROR.getCode());
			js.setMessage(HttpErrorCode.SERVICEERROR.getContent());
		}
		return js;
	}

	/**
	 * 添加支付类型
	 * 
	 * @param info
	 * @return
	 */
	@RequestMapping("/addpayTypeInfo")
	public JsonResult addpayTypeInfo(@RequestBody PayTypeInfo info, HttpServletRequest request) {
		JsonResult js = new JsonResult(HttpErrorCode.REQUESTSUCCESS.getCode(),
				HttpErrorCode.REQUESTSUCCESS.getContent());
		try {
			LoginAccountInfo user = (LoginAccountInfo) request.getSession().getAttribute("user");
			info.setAddTime(LocalDateTime.now());
			int i = payManageService.insertpayType(info);
			if (i <= 0) {
				js.setCode(HttpErrorCode.UPDATEDATAFAIL.getCode());
				js.setMessage(HttpErrorCode.UPDATEDATAFAIL.getContent());
				return js;
			}
			// log
			systemManageService.insertlogInfo(user.getLoginAccout(), user.getIp(), "支付管理-支付类型-添加");
		} catch (Exception e) {
			e.printStackTrace();
			js.setCode(HttpErrorCode.SERVICEERROR.getCode());
			js.setMessage(HttpErrorCode.SERVICEERROR.getContent());
		}
		return js;
	}

	/**
	 * 修改支付类型状态
	 * 
	 * @param info
	 * @return
	 */
	@RequestMapping("/updatepayTypestatusInfo")
	public JsonResult updatepayTypestatusInfo(@RequestBody PayTypeInfo info, HttpServletRequest request) {
		JsonResult js = new JsonResult(HttpErrorCode.REQUESTSUCCESS.getCode(),
				HttpErrorCode.REQUESTSUCCESS.getContent());
		try {
			LoginAccountInfo user = (LoginAccountInfo) request.getSession().getAttribute("user");
			info.setAddTime(LocalDateTime.now());
			int i = payManageService.updatepayTypestatusInfo(info);
			if (i <= 0) {
				js.setCode(HttpErrorCode.UPDATEDATAFAIL.getCode());
				js.setMessage(HttpErrorCode.UPDATEDATAFAIL.getContent());
				return js;
			}
			// log
			systemManageService.insertlogInfo(user.getLoginAccout(), user.getIp(), "支付管理-支付类型-状态修改");
		} catch (Exception e) {
			e.printStackTrace();
			js.setCode(HttpErrorCode.SERVICEERROR.getCode());
			js.setMessage(HttpErrorCode.SERVICEERROR.getContent());
		}
		return js;
	}

	/**
	 * 修改支付类型
	 * 
	 * @param info
	 * @param request
	 * @return
	 */
	@RequestMapping("/updatepayTypeInfo")
	public JsonResult updatepayTypeInfo(@RequestBody PayTypeInfo info, HttpServletRequest request) {
		JsonResult js = new JsonResult(HttpErrorCode.REQUESTSUCCESS.getCode(),
				HttpErrorCode.REQUESTSUCCESS.getContent());
		try {
			int i = payManageService.updatepayType(info);
			if (i <= 0) {
				js.setCode(HttpErrorCode.UPDATEDATAFAIL.getCode());
				js.setMessage(HttpErrorCode.UPDATEDATAFAIL.getContent());
				return js;
			}
			LoginAccountInfo user = (LoginAccountInfo) request.getSession().getAttribute("user");
			systemManageService.insertlogInfo(user.getLoginAccout(), user.getIp(), "支付管理-支付类型-修改");
		} catch (Exception e) {
			e.printStackTrace();
			js.setCode(HttpErrorCode.SERVICEERROR.getCode());
			js.setMessage(HttpErrorCode.SERVICEERROR.getContent());
		}
		return js;
	}

	/**
	 * 支付类型 排序
	 * 
	 * @param info
	 * @param request
	 * @return
	 */
	@RequestMapping("/updatepaySortTypeInfo")
	public JsonResult updatepaySortTypeInfo(@RequestBody String json, HttpServletRequest request) {
		JsonResult js = new JsonResult(HttpErrorCode.REQUESTSUCCESS.getCode(),
				HttpErrorCode.REQUESTSUCCESS.getContent());
		try {
			List<PayTypeInfo> info = new ArrayList<PayTypeInfo>();
			JSONObject jsobj = JSONObject.parseObject(json);
			int isnotPl = jsobj.getInteger("isnotPl");
			if (isnotPl == 1) { // 批量
				String idstr = jsobj.getString("id");
				int sort = jsobj.getInteger("sort");
				String id[] = idstr.split(",");
				for (int i = 0; i < id.length; i++) {
					PayTypeInfo obj = new PayTypeInfo();
					obj.setId(Integer.valueOf(id[i]));
					obj.setSort(sort);
					info.add(obj);
				}
			} else if (isnotPl == 0) {
				PayTypeInfo obj = JsonUtil.json2obj(json, PayTypeInfo.class);
				info.add(obj);
			} else {
				js.setCode(HttpErrorCode.UPDATEDATAFAIL.getCode());
				js.setMessage(HttpErrorCode.UPDATEDATAFAIL.getContent());
				return js;

			}
			int i = payManageService.updatepaysortType(info);
			if (i <= 0) {
				js.setCode(HttpErrorCode.UPDATEDATAFAIL.getCode());
				js.setMessage(HttpErrorCode.UPDATEDATAFAIL.getContent());
				return js;
			}
			LoginAccountInfo user = (LoginAccountInfo) request.getSession().getAttribute("user");
			systemManageService.insertlogInfo(user.getLoginAccout(), user.getIp(), "支付管理-支付类型-修改");
		} catch (Exception e) {
			e.printStackTrace();
			js.setCode(HttpErrorCode.SERVICEERROR.getCode());
			js.setMessage(HttpErrorCode.SERVICEERROR.getContent());
		}
		return js;
	}

	/**
	 * 删除支付类型
	 * 
	 * @param info
	 * @param request
	 * @return
	 */
	@RequestMapping("/deletepayTypeInfo")
	public JsonResult deletepayTypeInfo(@RequestBody PayTypeInfo info, HttpServletRequest request) {
		JsonResult js = new JsonResult(HttpErrorCode.REQUESTSUCCESS.getCode(),
				HttpErrorCode.REQUESTSUCCESS.getContent());
		try {
			int i = payManageService.deletepayType(info);
			if (i <= 0) {
				js.setCode(HttpErrorCode.UPDATEDATAFAIL.getCode());
				js.setMessage(HttpErrorCode.UPDATEDATAFAIL.getContent());
				return js;
			}
			LoginAccountInfo user = (LoginAccountInfo) request.getSession().getAttribute("user");
			systemManageService.insertlogInfo(user.getLoginAccout(), user.getIp(), "支付管理-支付类型-删除");
		} catch (Exception e) {
			e.printStackTrace();
			js.setCode(HttpErrorCode.SERVICEERROR.getCode());
			js.setMessage(HttpErrorCode.SERVICEERROR.getContent());
		}
		return js;
	}

	/******** ================支付渠道管理================ **********/

	@RequestMapping("/paychannelList")
	public JsonResult paychannelList(@RequestBody PayChannelInfo info) {
		JsonResult js = new JsonResult(HttpErrorCode.REQUESTSUCCESS.getCode(),
				HttpErrorCode.REQUESTSUCCESS.getContent());
		try {
			List<PayChannelInfo> list = payManageService.selectpaychanneList(info);
			if (list == null) {
				js.setCode(HttpErrorCode.PARAMERROR.getCode());
				js.setMessage(HttpErrorCode.PARAMERROR.getContent());
				return js;
			}
			list = list.stream().sorted(Comparator.comparing(PayChannelInfo::getSort).reversed())
					.collect(Collectors.toList());
			js.setData(list);
		} catch (Exception e) {
			e.printStackTrace();
			js.setCode(HttpErrorCode.SERVICEERROR.getCode());
			js.setMessage(HttpErrorCode.SERVICEERROR.getContent());
		}
		return js;
	}

	/**
	 * 根据支付类型查询收款渠道
	 * 
	 * @param info
	 * @return
	 */
	@RequestMapping("/selectpaychannelbypaytypeId")
	public JsonResult selectpaychannelbypaytypeId(@RequestBody PayChannelInfo info) {
		JsonResult js = new JsonResult(HttpErrorCode.REQUESTSUCCESS.getCode(),
				HttpErrorCode.REQUESTSUCCESS.getContent());
		try {
			List<PayChannelInfo> list = payManageService.selectpaychannelbypaytypeId(info.getId());
			if (list == null) {
				js.setCode(HttpErrorCode.PARAMERROR.getCode());
				js.setMessage(HttpErrorCode.PARAMERROR.getContent());
				return js;
			}
			js.setData(list);
		} catch (Exception e) {
			e.printStackTrace();
			js.setCode(HttpErrorCode.SERVICEERROR.getCode());
			js.setMessage(HttpErrorCode.SERVICEERROR.getContent());
		}
		return js;
	}

	/**
	 * 添加支付渠道
	 * 
	 * @param info
	 * @return
	 */
	@RequestMapping("/addpaychannelInfo")
	public JsonResult addpaychannelInfo(@RequestBody PayChannelInfo info, HttpServletRequest request) {
		JsonResult js = new JsonResult(HttpErrorCode.REQUESTSUCCESS.getCode(),
				HttpErrorCode.REQUESTSUCCESS.getContent());
		try {
			LoginAccountInfo user = (LoginAccountInfo) request.getSession().getAttribute("user");
			info.setAddPeopleName(user.getLoginAccout());
			info.setAddTime(LocalDateTime.now());
			int i = payManageService.insertpayChannelInfo(info);
			if (i <= 0) {
				js.setCode(HttpErrorCode.UPDATEDATAFAIL.getCode());
				js.setMessage(HttpErrorCode.UPDATEDATAFAIL.getContent());
				return js;
			}
			// log
			systemManageService.insertlogInfo(user.getLoginAccout(), user.getIp(), "支付管理-支付渠道管理-添加");
		} catch (Exception e) {
			e.printStackTrace();
			js.setCode(HttpErrorCode.SERVICEERROR.getCode());
			js.setMessage(HttpErrorCode.SERVICEERROR.getContent());
		}
		return js;
	}

	/**
	 * 更新支付渠道
	 * 
	 * @param info
	 * @return
	 */
	@RequestMapping("/updatepaychannelInfo")
	public JsonResult updatepaychannelInfo(@RequestBody PayChannelInfo info, HttpServletRequest request) {
		JsonResult js = new JsonResult(HttpErrorCode.REQUESTSUCCESS.getCode(),
				HttpErrorCode.REQUESTSUCCESS.getContent());
		try {
			int i = payManageService.updatepayChannelInfo(info);
			if (i <= 0) {
				js.setCode(HttpErrorCode.UPDATEDATAFAIL.getCode());
				js.setMessage(HttpErrorCode.UPDATEDATAFAIL.getContent());
				return js;
			}
			// log
			LoginAccountInfo user = (LoginAccountInfo) request.getSession().getAttribute("user");
			systemManageService.insertlogInfo(user.getLoginAccout(), user.getIp(), "支付管理-支付渠道管理-添加");
		} catch (Exception e) {
			e.printStackTrace();
			js.setCode(HttpErrorCode.SERVICEERROR.getCode());
			js.setMessage(HttpErrorCode.SERVICEERROR.getContent());
		}
		return js;
	}

	@RequestMapping("/updatepayChannelInfosort")
	public JsonResult updatepayChannelInfosort(@RequestBody String json, HttpServletRequest request) {
		JsonResult js = new JsonResult(HttpErrorCode.REQUESTSUCCESS.getCode(),
				HttpErrorCode.REQUESTSUCCESS.getContent());
		try {
			List<PayChannelInfo> info = new ArrayList<PayChannelInfo>();
			JSONObject jsobj = JSONObject.parseObject(json);
			int isnotPl = jsobj.getInteger("isnotPl");
			if (isnotPl == 1) { // 批量
				String idstr = jsobj.getString("id");
				int sort = jsobj.getInteger("sort");
				String id[] = idstr.split(",");
				for (int i = 0; i < id.length; i++) {
					PayChannelInfo obj = new PayChannelInfo();
					obj.setId(Integer.valueOf(id[i]));
					obj.setSort(sort);
					info.add(obj);
				}
			} else if (isnotPl == 0) {
				PayChannelInfo obj = JsonUtil.json2obj(json, PayChannelInfo.class);
				info.add(obj);
			} else {
				js.setCode(HttpErrorCode.UPDATEDATAFAIL.getCode());
				js.setMessage(HttpErrorCode.UPDATEDATAFAIL.getContent());
				return js;

			}

			int i = payManageService.updatepayChannelInfosort(info);
			if (i <= 0) {
				js.setCode(HttpErrorCode.UPDATEDATAFAIL.getCode());
				js.setMessage(HttpErrorCode.UPDATEDATAFAIL.getContent());
				return js;
			}
			// log
			LoginAccountInfo user = (LoginAccountInfo) request.getSession().getAttribute("user");
			systemManageService.insertlogInfo(user.getLoginAccout(), user.getIp(), "支付管理-支付渠道管理-排序");
		} catch (Exception e) {
			e.printStackTrace();
			js.setCode(HttpErrorCode.SERVICEERROR.getCode());
			js.setMessage(HttpErrorCode.SERVICEERROR.getContent());
		}
		return js;
	}

	/**
	 * 删除支付渠道
	 * 
	 * @param info
	 * @return
	 */
	@RequestMapping("/deletepayChannelInfo")
	public JsonResult deletepayChannelInfo(@RequestBody PayChannelInfo info, HttpServletRequest request) {
		JsonResult js = new JsonResult(HttpErrorCode.REQUESTSUCCESS.getCode(),
				HttpErrorCode.REQUESTSUCCESS.getContent());
		try {
			// 根据支付渠道查询是否存在下级收款账户

			int j = payManageService.selectisnotexitSkaccount(info.getId());
			if (j > 0) {
				js.setCode(HttpErrorCode.SKACCOUNTISEXITS.getCode());
				js.setMessage(HttpErrorCode.SKACCOUNTISEXITS.getContent());
				return js;
			}

			int i = payManageService.deletepayChannelInfo(info);
			if (i <= 0) {
				js.setCode(HttpErrorCode.UPDATEDATAFAIL.getCode());
				js.setMessage(HttpErrorCode.UPDATEDATAFAIL.getContent());
				return js;
			}
			// log
			LoginAccountInfo user = (LoginAccountInfo) request.getSession().getAttribute("user");
			systemManageService.insertlogInfo(user.getLoginAccout(), user.getIp(), "支付管理-支付渠道管理-添加");
		} catch (

		Exception e) {
			e.printStackTrace();
			js.setCode(HttpErrorCode.SERVICEERROR.getCode());
			js.setMessage(HttpErrorCode.SERVICEERROR.getContent());
		}
		return js;
	}

	/****************
	 * =============收款账户管理=============
	 *****************************/

	/**
	 * 
	 * 收款账户列表
	 * 
	 * @param info
	 * @return
	 */
	@RequestMapping("/skaccountlList")
	public JsonResult skaccountlList(@RequestBody SkAccountInfo info) {
		JsonResult js = new JsonResult(HttpErrorCode.REQUESTSUCCESS.getCode(),
				HttpErrorCode.REQUESTSUCCESS.getContent());
		try {
			List<SkAccountInfo> list = payManageService.selectskaccount(info);
			if (list == null || list.size() <= 0) {
				js.setCode(HttpErrorCode.REQUESTSUCCESS.getCode());
				js.setMessage(HttpErrorCode.PARAMERROR.getContent());
				return js;
			}
			list = list.stream().sorted(Comparator.comparing(SkAccountInfo::getSort).reversed())
					.collect(Collectors.toList());

			js.setData(list);
		} catch (Exception e) {
			e.printStackTrace();
			js.setCode(HttpErrorCode.SERVICEERROR.getCode());
			js.setMessage(HttpErrorCode.SERVICEERROR.getContent());
		}
		return js;
	}

	@RequestMapping("/selectallbankCard")
	public JsonResult selectallbankCard() {
		JsonResult js = new JsonResult(HttpErrorCode.REQUESTSUCCESS.getCode(),
				HttpErrorCode.REQUESTSUCCESS.getContent());
		try {
			List<SkAccountInfo> list = payManageService.selectallbankCard();
			if (list == null || list.size() <= 0) {
				js.setCode(HttpErrorCode.REQUESTSUCCESS.getCode());
				js.setMessage(HttpErrorCode.PARAMERROR.getContent());
				return js;
			}

			js.setData(list);
		} catch (Exception e) {
			e.printStackTrace();
			js.setCode(HttpErrorCode.SERVICEERROR.getCode());
			js.setMessage(HttpErrorCode.SERVICEERROR.getContent());
		}
		return js;
	}

	/**
	 * 收款账户详情
	 * 
	 * @param info
	 * @return
	 */
	@RequestMapping("/skaccountInfo")
	public JsonResult skaccountInfo(@RequestBody SkAccountInfo info) {
		JsonResult js = new JsonResult(HttpErrorCode.REQUESTSUCCESS.getCode(),
				HttpErrorCode.REQUESTSUCCESS.getContent());
		try {
			SkAccountInfo infos = payManageService.skaccountInfo(info);
			if (infos == null) {
				js.setCode(HttpErrorCode.REQUESTSUCCESS.getCode());
				js.setMessage(HttpErrorCode.PARAMERROR.getContent());
			}
			js.setData(infos);
		} catch (Exception e) {
			e.printStackTrace();
			js.setCode(HttpErrorCode.SERVICEERROR.getCode());
			js.setMessage(HttpErrorCode.SERVICEERROR.getContent());
		}
		return js;
	}

	/**
	 * 
	 * 添加收款账户
	 * 
	 * @param info
	 * @return
	 */
	@RequestMapping("/addskaccountInfo")
	public JsonResult addskaccountInfo(@RequestBody SkAccountInfo info, HttpServletRequest request) {
		JsonResult js = new JsonResult(HttpErrorCode.REQUESTSUCCESS.getCode(),
				HttpErrorCode.REQUESTSUCCESS.getContent());
		try {

			List<SkAccountInfo> list = payManageService.selectallskAccount();

			list = list.stream().filter(b -> b.getSkAccount().equals(info.getSkAccount())).collect(Collectors.toList());

			if (list != null && list.size() > 0) {
				js.setCode(HttpErrorCode.BANKCARDEXITS.getCode());
				js.setMessage(HttpErrorCode.BANKCARDEXITS.getContent());
				return js;
			}

			LoginAccountInfo user = (LoginAccountInfo) request.getSession().getAttribute("user");
			info.setAddPeopleName(user.getLoginAccout());
			info.setAddTime(LocalDateTime.now());

			int i = payManageService.insertskaccount(info);
			if (i <= 0) {
				js.setCode(HttpErrorCode.UPDATEDATAFAIL.getCode());
				js.setMessage(HttpErrorCode.UPDATEDATAFAIL.getContent());
				return js;
			}
			// log

			systemManageService.insertlogInfo(user.getLoginAccout(), user.getIp(), "支付管理-收款账户管理-添加");
		} catch (Exception e) {
			e.printStackTrace();
			js.setCode(HttpErrorCode.SERVICEERROR.getCode());
			js.setMessage(HttpErrorCode.SERVICEERROR.getContent());
		}
		return js;
	}

	/**
	 * 
	 * 删除收款账户
	 * 
	 * @param info
	 * @return
	 */
	@RequestMapping("/deleteskaccountInfo")
	public JsonResult deleteskaccountInfo(@RequestBody SkAccountInfo info, HttpServletRequest request) {
		JsonResult js = new JsonResult(HttpErrorCode.REQUESTSUCCESS.getCode(),
				HttpErrorCode.REQUESTSUCCESS.getContent());
		try {
			int i = payManageService.deleteskaccount(info);
			if (i <= 0) {
				js.setCode(HttpErrorCode.UPDATEDATAFAIL.getCode());
				js.setMessage(HttpErrorCode.UPDATEDATAFAIL.getContent());
				return js;
			}
			// log
			LoginAccountInfo user = (LoginAccountInfo) request.getSession().getAttribute("user");
			systemManageService.insertlogInfo(user.getLoginAccout(), user.getIp(), "支付管理-收款账户管理-删除");
		} catch (Exception e) {
			e.printStackTrace();
			js.setCode(HttpErrorCode.SERVICEERROR.getCode());
			js.setMessage(HttpErrorCode.SERVICEERROR.getContent());
		}
		return js;
	}

	/**
	 * 
	 * 更新收款账户
	 * 
	 * @param info
	 * @return
	 */
	@RequestMapping("/updateskaccount")
	public JsonResult updateskaccount(@RequestBody SkAccountInfo info, HttpServletRequest request) {
		JsonResult js = new JsonResult(HttpErrorCode.REQUESTSUCCESS.getCode(),
				HttpErrorCode.REQUESTSUCCESS.getContent());
		try {
			int i = payManageService.updateskaccount(info);
			if (i <= 0) {
				js.setCode(HttpErrorCode.UPDATEDATAFAIL.getCode());
				js.setMessage(HttpErrorCode.UPDATEDATAFAIL.getContent());
				return js;
			}
			// log
			LoginAccountInfo user = (LoginAccountInfo) request.getSession().getAttribute("user");
			systemManageService.insertlogInfo(user.getLoginAccout(), user.getIp(), "支付管理-收款账户管理-修改");
		} catch (Exception e) {
			e.printStackTrace();
			js.setCode(HttpErrorCode.SERVICEERROR.getCode());
			js.setMessage(HttpErrorCode.SERVICEERROR.getContent());
		}
		return js;
	}

	/**
	 * 
	 * 更新收款账户排序
	 * 
	 * @param info
	 * @return
	 */
	@RequestMapping("/updateskaccountsort")
	public JsonResult updateskaccountsort(@RequestBody String json, HttpServletRequest request) {
		JsonResult js = new JsonResult(HttpErrorCode.REQUESTSUCCESS.getCode(),
				HttpErrorCode.REQUESTSUCCESS.getContent());
		try {

			List<SkAccountInfo> info = new ArrayList<SkAccountInfo>();
			JSONObject jsobj = JSONObject.parseObject(json);
			int isnotPl = jsobj.getInteger("isnotPl");
			if (isnotPl == 1) { // 批量
				String idstr = jsobj.getString("id");
				int sort = jsobj.getInteger("sort");
				String id[] = idstr.split(",");
				for (int i = 0; i < id.length; i++) {
					SkAccountInfo obj = new SkAccountInfo();
					obj.setId(Integer.valueOf(id[i]));
					obj.setSort(sort);
					info.add(obj);
				}
			} else if (isnotPl == 0) {
				SkAccountInfo obj = JsonUtil.json2obj(json, SkAccountInfo.class);
				info.add(obj);
			} else {
				js.setCode(HttpErrorCode.UPDATEDATAFAIL.getCode());
				js.setMessage(HttpErrorCode.UPDATEDATAFAIL.getContent());
				return js;

			}
			int i = payManageService.updateskaccountsort(info);
			if (i <= 0) {
				js.setCode(HttpErrorCode.UPDATEDATAFAIL.getCode());
				js.setMessage(HttpErrorCode.UPDATEDATAFAIL.getContent());
				return js;
			}
			// log
			LoginAccountInfo user = (LoginAccountInfo) request.getSession().getAttribute("user");
			systemManageService.insertlogInfo(user.getLoginAccout(), user.getIp(), "支付管理-收款账户管理-修改");
		} catch (Exception e) {
			e.printStackTrace();
			js.setCode(HttpErrorCode.SERVICEERROR.getCode());
			js.setMessage(HttpErrorCode.SERVICEERROR.getContent());
		}
		return js;
	}

	/**
	 * 
	 * 更新收款状态
	 * 
	 * @param info
	 * @return
	 */
	@RequestMapping("/updateskaccountstatus")
	public JsonResult updateskaccountstatus(@RequestBody SkAccountInfo info, HttpServletRequest request) {
		JsonResult js = new JsonResult(HttpErrorCode.REQUESTSUCCESS.getCode(),
				HttpErrorCode.REQUESTSUCCESS.getContent());
		try {
			int i = payManageService.updateskaccountstatus(info);
			if (i <= 0) {
				js.setCode(HttpErrorCode.UPDATEDATAFAIL.getCode());
				js.setMessage(HttpErrorCode.UPDATEDATAFAIL.getContent());
				return js;
			}
			// log
			LoginAccountInfo user = (LoginAccountInfo) request.getSession().getAttribute("user");
			systemManageService.insertlogInfo(user.getLoginAccout(), user.getIp(), "支付管理-收款账户管理-修改");
		} catch (Exception e) {
			e.printStackTrace();
			js.setCode(HttpErrorCode.SERVICEERROR.getCode());
			js.setMessage(HttpErrorCode.SERVICEERROR.getContent());
		}
		return js;
	}

	/**************** =========充值优惠======== *********************/

	/**
	 * 
	 * 充值优惠列表
	 * 
	 * @param info
	 * @return
	 */
	@RequestMapping("/rechargediscountlList")
	public JsonResult rechargediscountlList() {
		JsonResult js = new JsonResult(HttpErrorCode.REQUESTSUCCESS.getCode(),
				HttpErrorCode.REQUESTSUCCESS.getContent());
		try {
			List<RechargeDiscountInfo> list = payManageService.selectrechargediscountList();
			if (list == null) {
				js.setCode(HttpErrorCode.REQUESTSUCCESS.getCode());
				js.setMessage(HttpErrorCode.PARAMERROR.getContent());
				return js;
			}
			js.setData(list);
		} catch (Exception e) {
			e.printStackTrace();
			js.setCode(HttpErrorCode.SERVICEERROR.getCode());
			js.setMessage(HttpErrorCode.SERVICEERROR.getContent());
		}
		return js;
	}

	/**
	 * 
	 * 添加充值优惠
	 * 
	 * @param info
	 * @return
	 */
	@RequestMapping("/addrechargediscountInfo")
	public JsonResult addrechargediscountInfo(@RequestBody RechargeDiscountInfo info, HttpServletRequest request) {
		JsonResult js = new JsonResult(HttpErrorCode.REQUESTSUCCESS.getCode(),
				HttpErrorCode.REQUESTSUCCESS.getContent());
		try {
			int i = payManageService.insertrechargediscountInfo(info);
			if (i <= 0) {
				js.setCode(HttpErrorCode.UPDATEDATAFAIL.getCode());
				js.setMessage(HttpErrorCode.UPDATEDATAFAIL.getContent());
				return js;
			}
			// log
			LoginAccountInfo user = (LoginAccountInfo) request.getSession().getAttribute("user");
			systemManageService.insertlogInfo(user.getLoginAccout(), user.getIp(), "支付管理-充值优惠-添加充值优惠");
		} catch (Exception e) {
			e.printStackTrace();
			js.setCode(HttpErrorCode.SERVICEERROR.getCode());
			js.setMessage(HttpErrorCode.SERVICEERROR.getContent());
		}
		return js;
	}

	/**
	 * 
	 * 删除充值优惠
	 * 
	 * @param info
	 * @return
	 */
	@RequestMapping("/deleterechargediscountInfo")
	public JsonResult deleterechargediscountInfo(@RequestBody RechargeDiscountInfo info, HttpServletRequest request) {
		JsonResult js = new JsonResult(HttpErrorCode.REQUESTSUCCESS.getCode(),
				HttpErrorCode.REQUESTSUCCESS.getContent());
		try {
			int i = payManageService.deleterechargediscountInfo(info);
			if (i <= 0) {
				js.setCode(HttpErrorCode.UPDATEDATAFAIL.getCode());
				js.setMessage(HttpErrorCode.UPDATEDATAFAIL.getContent());
				return js;
			}
			// log
			LoginAccountInfo user = (LoginAccountInfo) request.getSession().getAttribute("user");
			systemManageService.insertlogInfo(user.getLoginAccout(), user.getIp(), "支付管理-充值优惠-删除充值优惠");
		} catch (Exception e) {
			e.printStackTrace();
			js.setCode(HttpErrorCode.SERVICEERROR.getCode());
			js.setMessage(HttpErrorCode.SERVICEERROR.getContent());
		}
		return js;
	}

	/**
	 * 
	 * 修改充值优惠
	 * 
	 * @param info
	 * @return
	 */
	@RequestMapping("/updaterechargediscountInfo")
	public JsonResult updaterechargediscountInfo(@RequestBody RechargeDiscountInfo info, HttpServletRequest request) {
		JsonResult js = new JsonResult(HttpErrorCode.REQUESTSUCCESS.getCode(),
				HttpErrorCode.REQUESTSUCCESS.getContent());
		try {
			int i = payManageService.updaterechargediscountInfo(info);
			if (i <= 0) {
				js.setCode(HttpErrorCode.UPDATEDATAFAIL.getCode());
				js.setMessage(HttpErrorCode.UPDATEDATAFAIL.getContent());
				return js;
			}
			// log
			LoginAccountInfo user = (LoginAccountInfo) request.getSession().getAttribute("user");
			systemManageService.insertlogInfo(user.getLoginAccout(), user.getIp(), "支付管理-充值优惠-删除充值优惠");
		} catch (Exception e) {
			e.printStackTrace();
			js.setCode(HttpErrorCode.SERVICEERROR.getCode());
			js.setMessage(HttpErrorCode.SERVICEERROR.getContent());
		}
		return js;
	}

	/**************** =========在线支付管理======== *********************/

	/**
	 * 
	 * 支付管理列表
	 * 
	 * @param info
	 * @return
	 */
	@RequestMapping("/onlinepayList")
	public JsonResult onlinepayList() {
		JsonResult js = new JsonResult(HttpErrorCode.REQUESTSUCCESS.getCode(),
				HttpErrorCode.REQUESTSUCCESS.getContent());
		try {
			List<OnlinePayInfo> list = payManageService.selectonlinepayList();
			if (list == null) {
				js.setCode(HttpErrorCode.REQUESTSUCCESS.getCode());
				js.setMessage(HttpErrorCode.PARAMERROR.getContent());
				return js;
			}
			list = list.stream().sorted(Comparator.comparing(OnlinePayInfo::getSort).reversed())
					.collect(Collectors.toList());
			js.setData(list);
		} catch (Exception e) {
			e.printStackTrace();
			js.setCode(HttpErrorCode.SERVICEERROR.getCode());
			js.setMessage(HttpErrorCode.SERVICEERROR.getContent());
		}
		return js;
	}

	/**
	 * 
	 * 添加支付
	 * 
	 * @param info
	 * @return
	 */
	@RequestMapping("/addonlinepayInfo")
	public JsonResult addonlinepayInfo(@RequestBody OnlinePayInfo info, HttpServletRequest request) {
		JsonResult js = new JsonResult(HttpErrorCode.REQUESTSUCCESS.getCode(),
				HttpErrorCode.REQUESTSUCCESS.getContent());
		try {
			int i = payManageService.addonlinepayInfo(info);
			if (i <= 0) {
				js.setCode(HttpErrorCode.UPDATEDATAFAIL.getCode());
				js.setMessage(HttpErrorCode.UPDATEDATAFAIL.getContent());
				return js;
			}
			// log
			LoginAccountInfo user = (LoginAccountInfo) request.getSession().getAttribute("user");
			systemManageService.insertlogInfo(user.getLoginAccout(), user.getIp(), "支付管理-在线支付管理-添加");
		} catch (Exception e) {
			e.printStackTrace();
			js.setCode(HttpErrorCode.SERVICEERROR.getCode());
			js.setMessage(HttpErrorCode.SERVICEERROR.getContent());
		}
		return js;
	}

	/**
	 * 
	 * 更新支付
	 * 
	 * @param info
	 * @return
	 */
	@RequestMapping("/updateonlinepayInfo")
	public JsonResult updateonlinepayInfo(@RequestBody OnlinePayInfo info, HttpServletRequest request) {
		JsonResult js = new JsonResult(HttpErrorCode.REQUESTSUCCESS.getCode(),
				HttpErrorCode.REQUESTSUCCESS.getContent());
		try {
			int i = payManageService.updateonlinepayInfo(info);
			if (i <= 0) {
				js.setCode(HttpErrorCode.UPDATEDATAFAIL.getCode());
				js.setMessage(HttpErrorCode.UPDATEDATAFAIL.getContent());
				return js;
			}
			// log
			// log
			LoginAccountInfo user = (LoginAccountInfo) request.getSession().getAttribute("user");
			systemManageService.insertlogInfo(user.getLoginAccout(), user.getIp(), "支付管理-在线支付管理-修改");
		} catch (Exception e) {
			e.printStackTrace();
			js.setCode(HttpErrorCode.SERVICEERROR.getCode());
			js.setMessage(HttpErrorCode.SERVICEERROR.getContent());
		}
		return js;
	}

	@RequestMapping("/updatesortonlinepayInfo")
	public JsonResult updatesortonlinepayInfo(@RequestBody String json, HttpServletRequest request) {
		JsonResult js = new JsonResult(HttpErrorCode.REQUESTSUCCESS.getCode(),
				HttpErrorCode.REQUESTSUCCESS.getContent());
		try {
			List<OnlinePayInfo> info = new ArrayList<OnlinePayInfo>();
			JSONObject jsobj = JSONObject.parseObject(json);
			int isnotPl = jsobj.getInteger("isnotPl");
			if (isnotPl == 1) { // 批量
				String idstr = jsobj.getString("id");
				int sort = jsobj.getInteger("sort");
				String id[] = idstr.split(",");
				for (int i = 0; i < id.length; i++) {
					OnlinePayInfo obj = new OnlinePayInfo();
					obj.setId(Integer.valueOf(id[i]));
					obj.setSort(sort);
					info.add(obj);
				}
			} else if (isnotPl == 0) {
				OnlinePayInfo obj = JsonUtil.json2obj(json, OnlinePayInfo.class);
				info.add(obj);
			} else {
				js.setCode(HttpErrorCode.UPDATEDATAFAIL.getCode());
				js.setMessage(HttpErrorCode.UPDATEDATAFAIL.getContent());
				return js;

			}

			int i = payManageService.updatesortonlinepayInfo(info);
			if (i <= 0) {
				js.setCode(HttpErrorCode.UPDATEDATAFAIL.getCode());
				js.setMessage(HttpErrorCode.UPDATEDATAFAIL.getContent());
				return js;
			}
			// log
			// log
			LoginAccountInfo user = (LoginAccountInfo) request.getSession().getAttribute("user");
			systemManageService.insertlogInfo(user.getLoginAccout(), user.getIp(), "支付管理-在线支付管理-排序");
		} catch (Exception e) {
			e.printStackTrace();
			js.setCode(HttpErrorCode.SERVICEERROR.getCode());
			js.setMessage(HttpErrorCode.SERVICEERROR.getContent());
		}
		return js;
	}

	@RequestMapping("/updatestatusonlinepayInfo")
	public JsonResult updatestatusonlinepayInfo(@RequestBody OnlinePayInfo info, HttpServletRequest request) {
		JsonResult js = new JsonResult(HttpErrorCode.REQUESTSUCCESS.getCode(),
				HttpErrorCode.REQUESTSUCCESS.getContent());
		try {
			int i = payManageService.updatestatusonlinepayInfo(info);
			if (i <= 0) {
				js.setCode(HttpErrorCode.UPDATEDATAFAIL.getCode());
				js.setMessage(HttpErrorCode.UPDATEDATAFAIL.getContent());
				return js;
			}
			// log
			// log
			LoginAccountInfo user = (LoginAccountInfo) request.getSession().getAttribute("user");
			systemManageService.insertlogInfo(user.getLoginAccout(), user.getIp(), "支付管理-在线支付管理-启用禁用");
		} catch (Exception e) {
			e.printStackTrace();
			js.setCode(HttpErrorCode.SERVICEERROR.getCode());
			js.setMessage(HttpErrorCode.SERVICEERROR.getContent());
		}
		return js;
	}

	/**
	 * 
	 * 删除支付
	 * 
	 * @param info
	 * @return
	 */
	@RequestMapping("/deleteonlinepayInfo")
	public JsonResult deleteonlinepayInfo(@RequestBody OnlinePayInfo info, HttpServletRequest request) {
		JsonResult js = new JsonResult(HttpErrorCode.REQUESTSUCCESS.getCode(),
				HttpErrorCode.REQUESTSUCCESS.getContent());
		try {
			int i = payManageService.deleteonlinepayInfo(info);
			if (i <= 0) {
				js.setCode(HttpErrorCode.UPDATEDATAFAIL.getCode());
				js.setMessage(HttpErrorCode.UPDATEDATAFAIL.getContent());
				return js;
			}
			// log
			LoginAccountInfo user = (LoginAccountInfo) request.getSession().getAttribute("user");
			systemManageService.insertlogInfo(user.getLoginAccout(), user.getIp(), "支付管理-在线支付管理-删除");
		} catch (Exception e) {
			e.printStackTrace();
			js.setCode(HttpErrorCode.SERVICEERROR.getCode());
			js.setMessage(HttpErrorCode.SERVICEERROR.getContent());
		}
		return js;
	}

	/**
	 * 推送支付渠道消息
	 * 
	 * @return
	 */
	@RequestMapping("/payMessagePush")
	public JsonResult payMessagePush(HttpServletRequest request) {
		JsonResult js = new JsonResult(HttpErrorCode.REQUESTSUCCESS.getCode(),
				HttpErrorCode.REQUESTSUCCESS.getContent());
		payManageService.payMessagePush();
		// log
		LoginAccountInfo user = (LoginAccountInfo) request.getSession().getAttribute("user");
		systemManageService.insertlogInfo(user.getLoginAccout(), user.getIp(), "支付管理-支付渠道-推送变更");
		return js;
	}

}
